<template>
    <div class="fxgk-container">
      <div class="search_time" @click.stop="dateClick">
         <el-date-picker
            v-model="date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :editable="false"
            :clearable="false"
            :disabled="true"
            popper-class="eldate"
            size="small"
            >
          </el-date-picker>
      </div>
      <div class="fxgk_list">
        <div class="fxgk_one" v-for="(fxgk,index) in dataList" :key="index">
          <div class="fxgk_one_title">
              {{fxgk.enterType}}
          </div>
          <div class="fxgk_one_content">
            <div class="fxgk_content_one">
                <div class="content_num_unit">
                  <div class="content_num">
                      {{fxgk.tbs}}
                  </div>
                  <div class="content_unit">
                    家
                  </div>
                </div>
                  <div class="content_desc">
                    投保企业
                  </div>
            </div>
            <div class="fxgk_content_one" style="width:40%">
                <div class="content_num_unit">
                  <div class="content_num">
                      {{fxgk.qds}}
                  </div>
                  <div class="content_unit">
                    家
                  </div>
                </div>
                  <div class="content_desc">
                    签订服务合同企业
                  </div>
            </div>
            <div class="fxgk_content_one">
                <div class="content_num_unit">
                  <div class="content_num">
                      {{fxgk.qdl}}
                  </div>
                  <div class="content_unit">
                    %
                  </div>
                </div>
                  <div class="content_desc">
                    签订率
                  </div>
            </div>
            <div class="fxgk_content_one" style="width:50%">
                <div class="content_num_unit" style="color:#01BBD4">
                  <div class="content_num">
                      {{fxgk.ykzjcs}}
                  </div>
                  <div class="content_unit">
                    家
                  </div>
                </div>
                  <div class="content_desc">
                    已开展事故预防检查企业
                  </div>
            </div>
            <div class="fxgk_content_one" style="width:50%">
                <div class="content_num_unit" style="color:#FF9500">
                  <div class="content_num">
                      {{fxgk.wkzjcs}}
                  </div>
                  <div class="content_unit">
                    家
                  </div>
                </div>
                  <div class="content_desc">
                    未开展事故预防检查企业
                  </div>
            </div>
          </div>
        </div>
      </div>
      <van-calendar v-model="show" :allow-same-day="true" type="range" :min-date="minDate" :max-date="maxDate"  @confirm="onConfirm" />
    </div>
</template>
<script>
import {getFxgk} from '../../api/api'
export default {
  name: "MyIndex",
  
  data () {
    return {
      show:false,
      date: '',
      minDate: new Date('2021/01/01'),
      maxDate: new Date('2030/01/01'),
      dataList:[]
    };
  },
 
  watch:{
    date(){
      this.initData()
    }
  },
  mounted(){
     this.date = [this.formmterTimeYearStart(new Date),this.formmterTime(new Date)];
    //  this.initData()
  },
  methods:{
    async initData(){
      let params = {
        startTime : this.date[0],
        endTime : this.date[1]
      }
      let res = await getFxgk(params);
      this.dataList = res.data.data;
      console.log(res);
    },
    bqws (d) {
        if (d < 10) {
            return '0' + d
        } else {
            return d
        }
    },
    formmterTime(time){
        var date = new Date(time)
        var a = date.getFullYear()
        var b = date.getMonth() + 1
        var c = date.getDate()
        // var d = date.getDay()
        var e = a + '-' + this.bqws(b) + '-' + this.bqws(c)
        return e;
    },
    formmterTimeYearStart(time){
        var date = new Date(time)
        var a = date.getFullYear()
        var e = a + '-01-01'
        return e;
    },
    dateClick(){
      // console.log('123')
      this.show = true
    },
    formatDate(date) {
      return `${date.getMonth() + 1}/${date.getDate()}`;
    },
    onConfirm(date) {
      console.log(date)
      const [start, end] = date;
      this.show = false;
      this.date = [this.formmterTime(start),this.formmterTime(end)];
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .el-range-editor.is-disabled input {
  color: rgba(0,0,0,1) !important;
  border-color: #C0C4CC;
  background-color: #FFFFFF !important;
}
/deep/ .el-range-editor.is-disabled {
    background-color: #fff !important;
    border-color: #E4E7ED !important;
}
/deep/ .el-range-editor.is-disabled{
  background-color: #FFFFFF;
}
/deep/ .el-range-separator{
  color: #606266 !important;
}
.fxgk-container{
  width: 100%;
  display: flex;
  flex-direction: column;
  .search_time{
    display: flex;
    justify-content: center;
    padding: 5px;
  }
  .fxgk_list{
    flex: 1;
    overflow-y: auto;
    font-size: 15px;
    margin: 10px;
    
    .fxgk_one{
      display: flex;
      flex-direction: column;
      background: #FFFFFF;
      box-shadow: 0px 0px 4px 0px rgba(205, 205, 205, 0.5);
      border-radius: 2px;
      padding: 10px;
      margin-bottom: 10px;
        .fxgk_one_title{
          font-size: 16px;
          font-weight: 500;
          color: #494C5B;
          padding-left: 5px;
        }
      .fxgk_one_content{
        // padding: 5px;
        .fxgk_content_one{
          display: flex;
          flex-direction: column;
          float: left;
          width: 30%;
          padding: 10px 5px;
          box-sizing: border-box;
          .content_num_unit{
            display: flex;
            color: #2195F2;
            align-items: center;
            .content_num{
              font-size: 18px;
            }
            .content_unit{
              font-size: 10px;
            }
          }
          .content_desc{
            font-size: 12px;
          }
        }
      }
    }
  }
}
</style>